package com.otitan.la.forest.industry.controller;

import com.otitan.la.forest.industry.entity.ProjectApplicationEntity;
import com.otitan.la.forest.industry.dto.ProjectApplicationDTO;
import com.otitan.la.forest.industry.vo.ProjectApplicationVO;
import com.otitan.la.forest.industry.service.ProjectApplicationService;
import com.otitan.webapp.framework.basepro.model.DataResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * 项目申报
 *
 * @author jiacs
 * @email xxx
 * @date 2020-10-16 16:41:30
 */
@Slf4j
@Api(tags = "项目申报API")
@RestController
@RequestMapping("/project/application")
public class ProjectApplicationController {

    @Autowired
    private ProjectApplicationService projectApplicationService;


    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public DataResult add(@Valid @RequestBody ProjectApplicationEntity projectApplication, BindingResult bindingResult) {
        return projectApplicationService.add(projectApplication, bindingResult);
    }

    @ApiOperation(value = "批量删除")
    @DeleteMapping("/batchDelete")
    public DataResult batchDelete(@RequestBody @ApiParam(value = "ID集合") List<String> ids) {
        return projectApplicationService.batchDelete(ids);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/delete/{id}")
    public DataResult delete(@PathVariable("id") String id) {
        List<String> ids = new ArrayList<String>() {{
            add(id);
        }};
        return projectApplicationService.batchDelete(ids);
    }

    @ApiOperation(value = "更新")
    @PutMapping("/update")
    public DataResult editor(@Valid @RequestBody ProjectApplicationEntity projectApplication, BindingResult bindingResult) {
        return projectApplicationService.editor(projectApplication, bindingResult);
    }

    @ApiOperation(value = "列表查询（分页）")
    @PostMapping("/findPage/{page}/{size}")
    public DataResult<Page<ProjectApplicationVO>> findPageData(@PathVariable("page") long page,
                                     @PathVariable("size") long size,
                                     @RequestBody ProjectApplicationDTO projectApplication) {
        return projectApplicationService.findPageData(page, size, projectApplication);
    }

    @ApiOperation(value = "根据ID查询")
    @GetMapping("/findOne/{id}")
    public DataResult<ProjectApplicationVO> findOne(@PathVariable("id") String id) {
        return projectApplicationService.findOne(id);
    }

}
